package com.xiaobai.customer.response;

import lombok.Data;

@Data
public class ResponseResult<T> {
    private Integer code;
    private String msg;
    private T data;

    private ResponseResult(Integer code, String msg, T data) {
        this(code, msg);
        this.data = data;
    }

    private ResponseResult(Integer code, String msg) {
        this(code);
        this.msg = msg;
    }

    private ResponseResult(Integer code) {
        this.code = code;
    }

    private ResponseResult(T data) {
        this();
        this.data = data;
    }

    private ResponseResult() {
        this.code = 200;
    }

    public static <T> ResponseResult<T> success(T data) {
        return new ResponseResult<>(data);
    }

    public static <T> ResponseResult<T> fail(String msg) {
        return new ResponseResult<>(500, msg);
    }

    public static <T> ResponseResult<T> fail(Integer code, String msg) {
        return new ResponseResult<>(code, msg);
    }
}
